package com.koalton.steward.flow.controller;

import com.alibaba.fastjson.JSON;
import com.koalton.steward.common.dto.ResponseResult;
import com.koalton.steward.common.util.SequenceUtil;
import com.koalton.steward.flow.model.Flow;
import com.koalton.steward.flow.model.ItemType;
import com.koalton.steward.flow.service.FlowItemService;
import com.koalton.steward.flow.service.FlowService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by koalton on 2017/7/11.
 */

@RestController
public class FlowController {

    @Autowired
    FlowService flowService ;

    @Autowired
    FlowItemService flowItemService ;

    @RequestMapping(value="/query/{flowId}",method = RequestMethod.GET)
    public Flow get(@PathVariable Long flowId){
        Flow flow = flowService.get(flowId);
        System.out.println(flow);
        return flow;
    }

    @RequestMapping(value = "/in",method = RequestMethod.POST,consumes = "application/json")
    public ResponseResult recordIn(@RequestBody Flow flow){
        flow = this.reBuildFlow(flow);
        flowService.add(flow);
        System.out.println(flow);
        return ResponseResult.success();
    }
    @RequestMapping("/out")
    public String addOut(){
        return "";
    }

    @Test
    public void show(){
        Flow flow = new Flow();
        flow.setID(12L);
        System.out.println(JSON.toJSONString(flow));
    }

    private Flow reBuildFlow(Flow flow){
        Long id = SequenceUtil.nextSeq();
        flow.setID(id);
        flow.setRecorderID(99999L);

        return flow;
    }

}
